<?php
require('../../../global.php');
checkAdminAuthorizeAndJump('questionBank.edit');
if (checkVar($_GET['id'])) {
    $row = $db->get('tb_class', '*', array('tbid' => $_GET['id']));
   
}

?>
<!DOCTYPE html>
<html>
<head>
    <?php require('admin/_head.php'); ?>
    <title>课程管理 - <?php echo getconfig('title'); ?>管理后台</title>
        <link href="<?php echo SITEROOTURL; ?>/admin/js/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
        <link href="<?php echo SITEROOTURL; ?>/admin/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h3>
                    <button type="button" class="btn btn-white btn-sm closelayer">返回</button>
            <?php 
                if (checkVar($_GET['id'])) {
                    echo '编辑';
                } else {
                    echo '新增';
                }
            ?>
            	公开课
                </h3>
            </div>
            <div class="ibox-content">
                <div class="row row-lg">
                    <div class="col-sm-12">
                        <form class="form-horizontal" id="editForm" action="ajax.php">
                            <input type="hidden" name="ac" value="add">
                            <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">课程名称</label>
                                <div class="col-sm-10">
                                    <input type="text" name="name" id="name" placeholder="请输入课程名称" class="form-control" value="<?php echo $row['name']; ?>" dataType="*" nullmsg="请输入课程名称" errormsg="请输入课程名称">
                                    <span class="help-block m-b-none"></span>
                                </div>
                           </div>
                           <div class="form-group">
                                <label class="col-sm-2 control-label">上课地址</label>
                                <div class="col-sm-10">
                                    <input type="text" name="address" id="address" placeholder="请输入上课地址" class="form-control" value="<?php echo $row['address']; ?>" dataType="*" nullmsg="请输入上课地址" errormsg="请输入上课地址">
                                    <span class="help-block m-b-none"></span>
                                </div>
                           </div>
                           <div class="form-group">
                                <label class="col-sm-2 control-label">课程简介</label>
                                <div class="col-sm-10">
                                    <textarea name="introduction" placeholder="请输入课程简介" class="form-control"> <?php echo $row['introduction']; ?></textarea>
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                           <div class="form-group">
                                <label class="col-sm-2 control-label">上课时间</label>
                                <div class="col-sm-10">
                                    <input type="text" name="class_time" id="class_time" placeholder="请输入上课时间" class="form-control" value="<?php echo $row['class_time']; ?>" dataType="*" nullmsg="请输入上课时间" errormsg="请输入上课时间">
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                           <div class="form-group">
                                <label class="col-sm-2 control-label">课程费用(单位:元)</label>
                                <div class="col-sm-10">
                                    <input type="text" name="price" id="price" placeholder="请输入课程费用" class="form-control" value="<?php echo $row['price']/100; ?>" dataType=" /^([1-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])$/" nullmsg="请输入课程费用" errormsg="请输入课程费用">
                                    <span class="help-block m-b-none"></span>
                                </div>
                           </div>
                           <div class="form-group">
                                <label class="col-sm-2 control-label">预付金额(单位:元)</label>
                                <div class="col-sm-10">
                                    <input type="text" name="subsist" id="subsist" placeholder="请输入预付金额" class="form-control" value="<?php echo $row['subsist']/100; ?>" dataType=" /^([1-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])$/" nullmsg="请输入课程费用" errormsg="请输入预付金额">
                                    <span class="help-block m-b-none"></span>
                                </div>
                           </div>
                           <div class="form-group">
                                <label class="col-sm-2 control-label">上课次数</label>
                                <div class="col-sm-10">
                                    <input type="text" name="number" id="number" placeholder="请输入上课次数" class="form-control" value="<?php echo $row['number']; ?>" dataType="n" nullmsg="请输入上课次数" errormsg="请输入上课次数">
                                    <span class="help-block m-b-none"></span>
                                </div>
                           </div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary btn-lg" type="submit" id="btn-submit">保存内容</button>
                                    <button class="btn btn-white btn-lg closelayer" type="button">取消</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php require('admin/_js.php'); ?>
    <script src="<?php echo SITEROOTURL; ?>/admin/js/content.js?v=1.0.0"></script>
    <script src="<?php echo SITEROOTURL; ?>/admin/js/plugins/validform/Validform_min.js"></script>
    <script src="<?php echo SITEROOTURL; ?>/admin/js/plugins/validform/Validform_Datatype.js"></script>
    <script src="<?php echo SITEROOTURL; ?>/admin/js/plugins/webuploader/webuploader.min.js"></script>

    <script src="<?php echo SITEROOTURL; ?>/admin/js/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
    <script src="<?php echo SITEROOTURL; ?>/admin/js/plugins/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
    <script>
    $(function(){
        var closeLayer = function(){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.closeLayer(index);
        }
        $('.closelayer').click(function(event){
            closeLayer();
        });
        $('#class_time').datetimepicker({
            language : 'zh-CN',
            format : 'yyyy-mm-dd hh:ii',
            weekStart : 1,
            startView : 2,
            todayHighlight : true,
            autoclose : true
        }).on('changeDate', function(){
            form.check(false, $(this));
        });
        var form = $('#editForm').Validform({
    		btnSubmit: '#btn-submit',
    		postonce: false,
            ignoreHidden:true,
    		showAllError: true,
    		//msg：提示信息;
    		//o:{obj:*,type:*,curform:*}, obj指向的是当前验证的表单元素（或表单对象），type指示提示的状态，值为1、2、3、4， 1：正在检测/提交数据，2：通过验证，3：验证失败，4：提示ignore状态, curform为当前form对象;
    		//cssctl:内置的提示信息样式控制函数，该函数需传入两个参数：显示提示信息的对象 和 当前提示的状态（既形参o中的type）;
    		tiptype: function(msg, o){
    			if(!o.obj.is('form')){//验证表单元素时o.obj为该表单元素，全部验证通过提交表单时o.obj为该表单对象;
    				var B = o.obj.parents('.form-group');
    				var T = B.find('.help-block');
    				if(o.type == 2){
    					B.removeClass('has-error').addClass('has-success');
    					T.html('');
    				}else{
    					B.removeClass('has-success').addClass('has-error');
    					T.html("<i class='fa fa-times-circle'></i> " + msg);
    				}
    			}
    		},
    		ajaxPost: true,
            beforeSubmit:function(){
                var type=$("#type").val()

        	},
    		callback: function(data){
				if(data.status == 'y'){
                    parent.swal('操作成功', '', 'success');
                    closeLayer();
				}else{
                    swal('操作失败', '', 'error');
				}
    		}
    	});
    });
    </script>
</body>
</html>
